if (!jsx3.lang.Class.forName("ux.cdb.admin.queries.agreement.DetailDialog")) {

jsx3.Class.defineClass(
	"ux.cdb.admin.queries.agreement.DetailDialog", jsx3.gui.Dialog, [],
	function (objRoot) {

		objRoot.prototype.isEdit=null;
		objRoot.prototype.lastType=null;//save last time which type user selected , if type not changed,do not load panel agaim
		objRoot.prototype.loadCount=0;//times counter use for judge whether all the detail panel loaded

		objRoot.prototype.initialize = function(){
			var me = this;
			/* ux.megatron.Main.loadUIResourceAsync(me.getDescendantOfName('schemaDetailTab1').getContentPane(), "ux.cdb.admin", "ux/cdb/admin/mechanism/schema/loanassist/ui/SchemaLoanAssistBaseinfo.xml", me, function(){
				ux.megatron.Main.loadUIResourceAsync(me.getDescendantOfName('schemaDetailTab2').getContentPane(), "ux.cdb.admin", "ux/cdb/admin/mechanism/schema/loanassist/ui/SchemaLoanAssistInterest.xml", me, function(){
					ux.megatron.Main.loadUIResourceAsync(me.getDescendantOfName('schemaDetailTab3').getContentPane(), "ux.cdb.admin", "ux/cdb/admin/mechanism/schema/loanassist/ui/SchemaLoanAssistCompensate.xml", me, me.onAfterLoaded);
				});
			}); */
			this.onAfterLoaded();
		};
		
		/**
		 * This method will be called after UI file has deserialized.
		 */
		objRoot.prototype.onAfterDeserialize = function() {
		};
		
		objRoot.prototype.onAfterLoaded = function() {
			this.parent = ux.megatron.Main.getServer().getBodyBlock().get('blkAgreementWorld');
			this.matrix = this.parent.matrix;
			jsx3.log('aggreement#DetailDialog loaded. matrix : ' + this.matrix);
			this.ruleSelected();
		};

		objRoot.prototype.ruleSelected=function()
		{//user selected some record
			var detailPanel = this.getDescendantOfName("tab_Schema_Detail");
			var orgType = this.matrix.getSelectedNodes().get(0).getAttribute("cooperAgreementCode");
			jsx3.log('selectedRecord : ' + this.matrix.getSelectedNodes().get(0));
			if (orgType==this.lastType)
			{//type equale, do not load panel again ,load data directly
				if (orgType == "004") {
					this.loadCount=3;
					this.assistTypeLoaded();
					return;
				}
				return;	
			}
			
			//init the tab by organization's type
			if (orgType == "004") {
				this.showPaneTypeAssist();
				//display the tab
				detailPanel.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
			}
			else{
				detailPanel.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
			}
			this.lastType=orgType;
		}
		
		//invest type
		objRoot.prototype.showPaneTypeInvest=function()
		{
			var me=this;
			var tabname=[
						{name:"schemaDetailTab1",text:"@cdb@Mechanism@Schema@BaseinfoTitle",url:"ux/cdb/admin/mechanism/schema/invest/ui/SchemaInvestBaseinfo.xml"},
						{name:"schemaDetailTab2",text:"@cdb@Mechanism@Schema@PrincipleTitle",url:"ux/cdb/admin/mechanism/schema/invest/ui/SchemaInvestPrinciple.xml"},
						{name:"schemaDetailTab3",text:"@cdb@Mechanism@Schema@CooperateTitle",url:"ux/cdb/admin/mechanism/schema/invest/ui/SchemaInvestCooperation.xml"},
						{name:"schemaDetailTab4",text:"@cdb@Mechanism@Schema@ReserveTitle",url:"ux/cdb/admin/mechanism/schema/invest/ui/SchemaInvestReserve.xml"},
						{name:"schemaDetailTab5",text:"@cdb@Mechanism@Schema@AssureTitle",url:"ux/cdb/admin/mechanism/schema/invest/ui/SchemaInvestCooOrgAssure.xml"},
						{name:"schemaDetailTab6",text:"@cdb@Mechanism@Schema@CompensateTitle",url:"ux/cdb/admin/mechanism/schema/invest/ui/SchemaInvestCompensate.xml"},
						{name:"schemaDetailTab7",text:"@cdb@Mechanism@Schema@Invest@Attachment",url:"ux/cdb/admin/mechanism/schema/invest/ui/ShemaInvestAttachment.xml"}
						];
			this.showTabs(tabname,null);
		};
		
		//assist type
		objRoot.prototype.showPaneTypeAssist=function()
		{
			var me=this;
			var tabname=[
						{name:"schemaDetailTab1",text:"@cdb@Mechanism@Schema@BaseinfoTitle",url:"ux/cdb/admin/mechanism/schema/loanassist/ui/SchemaLoanAssistBaseinfo.xml"},
						{name:"schemaDetailTab2",text:"@cdb@Mechanism@Assist@InterestTitle",url:"ux/cdb/admin/mechanism/schema/loanassist/ui/SchemaLoanAssistInterest.xml"},
						{name:"schemaDetailTab3",text:"@cdb@Mechanism@Assist@ReserveRatioTitle",url:"ux/cdb/admin/mechanism/schema/loanassist/ui/SchemaLoanAssistCompensate.xml"},
						{name:"schemaDetailTab4",text:"",url:"none"},
						{name:"schemaDetailTab5",text:"",url:"none"},
						{name:"schemaDetailTab6",text:"",url:"none"},
						{name:"schemaDetailTab7",text:"",url:"none"}
						];
			//this.showTabs(tabname,this.assistTypeLoaded);
			this.showTabs(tabname,me.assistTypeLoaded);
		};
		
		//assist type loaded
		objRoot.prototype.assistTypeLoaded=function()
		{//when assist detail panel loaded,call the service operation to get detail data
			this.loadCount+=1;
			if (this.loadCount = 4) {
				this.loadCount=0;
				//all panel loaded
				var me = this;
				var record = this.matrix.getSelectedNodes().get(0);
				var assistDetail = this.getDescendantOfName("schemaDetailTab1").getContentPane().getDescendantOfName("blkAssistDetailBaseinfo");
				
				assistDetail.setDataEntityType(ux.cdb.admin.dataautomate.GenericDetail.CooperAgreement);
				assistDetail.setDataEntityId(record.getAttribute("partyId") + ";" + record.getAttribute("cooperAgreementNbr"));//id=shcemaid$$CooOrgID
				assistDetail.setProcessHandler(function(obj){
					return me.showAssistMatrix(obj);
				});
				assistDetail.refreshData();
			}
			return;
		};
		
		/**
		 * receive the detail data from server,assemble the data from matrix
		 */
		objRoot.prototype.showAssistMatrix=function(data)
		{
			var cacheIntr=new jsx3.xml.CDF.Document.newDocument();
			var cacheCmp=new jsx3.xml.CDF.Document.newDocument();
			var intrMatrix=this.getDescendantOfName("schemaDetailTab2").getContentPane().getDescendantOfName("mtx_Schema_Interest");
			var cmpMatrix=this.getDescendantOfName("schemaDetailTab3").getContentPane().getDescendantOfName("mtx_Schema_Compensate");
			//generator the cdf for the loan assist interest ratio
			cacheIntr.insertRecord({
					jsxid:0,											
					jsxtype: ux.megatron.Main.getServer().getDynamicProperty("@cdb@Dialog@MatrixColumn1"),
					jsxcenter:data.centralFinanceSubsidyPct1,					
					jsxprovince:data.provinceFinanceSubsidyPct1,
					jsxcity:data.cityFinanceSubsidyPctSubsidy1,
					jsxcounty:data.countyFinanceSubsidyPct1,
					jsxothers:data.otherPartSubsidyPct1		
			});
			cacheIntr.insertRecord({
					jsxid:1,											
					jsxtype:ux.megatron.Main.getServer().getDynamicProperty("@cdb@Dialog@MatrixColumn2"),
					jsxcenter:data.centralFinanceSubsidyPct2,					
					jsxprovince:data.provinceFinanceSubsidyPct2,
					jsxcity:data.cityFinanceSubsidyPctSubsidy2,
					jsxcounty:data.countyFinanceSubsidyPct2,
					jsxothers:data.otherPartSubsidyPct2		
			});
			cacheIntr.insertRecord({
					jsxid:2,											
					jsxtype:ux.megatron.Main.getServer().getDynamicProperty("@cdb@Dialog@MatrixColumn3"),
					jsxcenter:data.centralFinanceSubsidyPct3,					
					jsxprovince:data.provinceFinanceSubsidyPct3,
					jsxcity:data.cityFinanceSubsidyPctSubsidy3,
					jsxcounty:data.countyFinanceSubsidyPct3,
					jsxothers:data.otherPartSubsidyPct3		
			});

			//put the data into the cache
			ux.megatron.Main.getServer().getCache().setDocument("cchSchemaLoadAssistInterestShowDetail",cacheIntr);
			intrMatrix.repaintData();
			if (data.otherSharePartyNameSubsidy1 == null) 
			{
				data.otherSharePartyNameSubsidy1 = "";
			}
			intrMatrix.getDescendantOfName("titleothers").setText(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@Assist@InterestMatrixTitle5")+"<br>"+data.otherSharePartyNameSubsidy1,true);
			//generator the cache for loan assist compensate
			cacheCmp.insertRecord({
					jsxid:0,											
					jsxtype:ux.megatron.Main.getServer().getDynamicProperty("@cdb@Dialog@MatrixColumn1"),
					jsxcenter:data.centralFinanceSharedPct1,					
					jsxprovince:data.provinceFinanceSharePct1,
					jsxcity:data.cityFinanceSubsidyPct1,
					jsxcounty:data.countyFinanceSharePct1,
					jsxothers:data.otherPartSharePct1		
			});
			cacheCmp.insertRecord({
					jsxid:1,											
					jsxtype:ux.megatron.Main.getServer().getDynamicProperty("@cdb@Dialog@MatrixColumn2"),
					jsxcenter:data.centralFinanceSharedPct2,					
					jsxprovince:data.provinceFinanceSharePct2,
					jsxcity:data.cityFinanceSubsidyPct2,
					jsxcounty:data.countyFinanceSharePct2,
					jsxothers:data.otherPartSharePct2		
			});
			cacheCmp.insertRecord({
					jsxid:2,											
					jsxtype:ux.megatron.Main.getServer().getDynamicProperty("@cdb@Dialog@MatrixColumn3"),
					jsxcenter:data.centralFinanceSharedPct3,					
					jsxprovince:data.provinceFinanceSharePct3,
					jsxcity:data.cityFinanceSubsidyPct3,
					jsxcounty:data.countyFinanceSharePct3,
					jsxothers:data.otherPartSharePct3		
			});

			//put the data into the cache
			ux.megatron.Main.getServer().getCache().setDocument("cchSchemaLoadAssistCmpShowDetail",cacheCmp);
			cmpMatrix.repaintData();
			if (data.otherSharePartyName1 == null) 
			{
				data.otherSharePartyName1 = "";
			}
			cmpMatrix.getDescendantOfName("titleothers").setText(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@Assist@InterestMatrixTitle5")+"<br>"+data.otherSharePartyName1,true);
			this.getDescendantOfName("schemaDetailTab3").getContentPane().getDescendantOfName("blkCmpRatio").getDescendantOfName("lblValue").setText(data.riskSharePct/* +"%" */,true);
			this.getDescendantOfName("schemaDetailTab3").getContentPane().getDescendantOfName("blkOverflowRisk").setDataByObject({cdbChargeLossPct:data.cdbChargeLossPct,cooperOrgChargeLossPct:data.cooperOrgChargeLossPct});

			return data;
		}

		//assure type
		objRoot.prototype.showPaneTypeAssure=function()
		{
			var me=this;
			var tabname=[
						{name:"schemaDetailTab1",text:"@cdb@Mechanism@Schema@BaseinfoTitle",url:"ux/cdb/admin/mechanism/schema/assure/ui/SchemaAssureBaseinfo.xml"},
						{name:"schemaDetailTab2",text:"@cdb@Mechanism@Schema@Assure@AgentLoanTitle",url:"ux/cdb/admin/mechanism/schema/assure/ui/SchemaAssureAgentLoan.xml"},
						{name:"schemaDetailTab3",text:"@cdb@Mechanism@Schema@CompensateTitle",url:"ux/cdb/admin/mechanism/schema/assure/ui/SchemaAssureCompensate.xml"},
						{name:"schemaDetailTab4",text:"@cdb@Mechanism@Schema@Invest@Attachment",url:"ux/cdb/admin/mechanism/schema/invest/ui/ShemaInvestAttachment.xml"},
						{name:"schemaDetailTab5",text:"",url:"none"},
						{name:"schemaDetailTab6",text:"",url:"none"},
						{name:"schemaDetailTab7",text:"",url:"none"}
						];
			this.showTabs(tabname,null);
		}
		
		//credit type
		objRoot.prototype.showPaneTypeMiniCredit=function()
		{
			var me=this;
			var tabname=[
						{name:"schemaDetailTab1",text:"@cdb@Mechanism@Schema@BaseinfoTitle",url:"ux/cdb/admin/mechanism/schema/invest/ui/SchemaInvestBaseinfo.xml"},
						{name:"schemaDetailTab2",text:"@cdb@Mechanism@Schema@CooperateInfoTitle",url:"ux/cdb/admin/mechanism/schema/minicredit/ui/SchemaMiniCreditCooperationInfo.xml"},
						{name:"schemaDetailTab3",text:"@cdb@Mechanism@Schema@Assure@AgentLoanTitle",url:"ux/cdb/admin/mechanism/schema/minicredit/ui/SchemaMiniCreditAgentLoan.xml"},
						{name:"schemaDetailTab4",text:"@cdb@Mechanism@Schema@AgentAndQueryFee",url:"ux/cdb/admin/mechanism/schema/minicredit/ui/SchemaMiniCreditAgentfee.xml"},
						{name:"schemaDetailTab5",text:"@cdb@Mechanism@Schema@CompensateTitle",url:"ux/cdb/admin/mechanism/schema/minicredit/ui/SchemaMiniCreditCompensate.xml"},
						{name:"schemaDetailTab6",text:"@cdb@Mechanism@Schema@Invest@Attachment",url:"ux/cdb/admin/mechanism/schema/invest/ui/ShemaInvestAttachment.xml"},
						{name:"schemaDetailTab7",text:"",url:"none"}
						];
			this.showTabs(tabname,null);
		}

		objRoot.prototype.showTabs = function(tabs,callbackfunc)
		{
			var server=ux.megatron.Main.getServer();
			var me=this;
			for(var i=0;i<tabs.length;i++)
			{	
				var tabBaseinfo=this.getDescendantOfName(tabs[i].name);
				tabBaseinfo.getContentPane().removeChildren();
				if (tabs[i].url != "none") {
					ux.megatron.Main.loadUIResourceAsync(tabBaseinfo.getContentPane(), "ux.cdb.admin", tabs[i].url, me, callbackfunc);
					tabBaseinfo.setText(server.getDynamicProperty(tabs[i].text));
					tabBaseinfo.repaint();
					tabBaseinfo.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
				}
				else
				{
					tabBaseinfo.setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
				}
			}
		}

		//call service interface GetCooperAgreementUCC to get the list -get all
		objRoot.prototype.callGetCooperAgreementUCC=function()
		{	
			ux.megatron.util.Dwr.callDwr("GetCooperAgreementUCC", "getCooperAgreementListByCondition", [null,null,null,null,1,this.pageSize], this, this.loadSchemaList);
		}
		/**
		 * when user click search do this function
		 */
		objRoot.prototype.onSearch=function()
		{	
			this.lastType=null;
			var code=this.getDescendantOfName("blkSearchCode").getDescendantOfName("txtValue").getValue();
			var name=this.getDescendantOfName("blkSearchName").getDescendantOfName("txtValue").getValue();
			var type=this.getDescendantOfName("blkSearchType").getDescendantOfName("selValue").getValue();
			if (code=="")
			{
				code=null;
			}
			if (name=="")
			{
				name=null;
			}
			if (type=="")
			{
				type=null;
			}
			//GetCooperAgreementUCC.getCooperAgreementListByCondition( internalOrgId 内部机构编号-分行, cooperAgreementTypeCode 合作协议类型, cooperAgreementNbr 合作协议编号, partybName 合作机构名称, String curPage, String pageSize)
			ux.megatron.util.Dwr.callDwr("GetCooperAgreementUCC", "getCooperAgreementListByCondition", [null,type,code,name,1,this.pageSize], this, this.loadSchemaList);
		}
		//load data
		objRoot.prototype.loadSchemaList=function(objEvent)
		{
			var detailPanel=this.getDescendantOfName("tab_Schema_Detail");
			var notice=this.getDescendantOfName("blk_schema_notice");
			//show the notice panel hiiden the detail panel
			detailPanel.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
			notice.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
			//clear the type
			this.lastType=null;
			
			//got the data  assemble the cache 
			var cache=jsx3.xml.CDF.Document.newDocument();
			var record;
			var recordinfo;
			//alert(ux.megatron.util.JSON.JSONtoString(objEvent));
			this.totalCount=objEvent.content.page.count;//take the pageinfo
			recordinfo=objEvent.content.data;//take the records
			
			this.totalPage=Math.ceil(this.totalCount/this.pageSize);
			
			this.getDescendantOfName("lblTotPageNo").setText("/"+this.totalPage,true);//show total page
			this.getDescendantOfName("txtPageNoInput").setValue(this.currPage);//show currpage
			if (recordinfo != null) {
			
				if (recordinfo.length) {
					//multi-record
					for (var i = 0; i < recordinfo.length; i++) {
						record = {
							jsxid: i,
							jsxOrgid:recordinfo[i].partyId,//合作机构代码
							jsxcode: recordinfo[i].cooperAgreementNbr, //合作协议代码
							jsxname: recordinfo[i].partybName, //合作机构名称
							jsxBranch: recordinfo[i].internalOrgId, //分行代码
							jsxType: recordinfo[i].cooperAgreementTypeCode, //合作协议类型代码
							jsxBranchName:recordinfo[i].internalOrgName,//分行名称
							jsxTypeName:recordinfo[i].cooperOrgTypeName//合作协议类型名称
						};
						
						cache.insertRecord(record);
					}
				}
			}
			ux.megatron.Main.getServer().getCache().setDocument("cchSchemaList",cache);
			this.matrix.repaint();
		}
		 
		//wizard loaded
		objRoot.prototype.onBuilderLoaded=function(objEvent)
		{

			var wizard=null
			var parent = ux.megatron.Main.getServer().getBodyBlock();

			wizard=parent.getDescendantsOfType("ux.cdb.admin.mechanism.schema.SchemaWizard");

			wizard[0].isEdit=this.isEdit;
			if (this.isEdit) {
				wizard[0].schemaType = this.matrix.getCheckedNodes().get(0).getAttribute("jsxType");
				wizard[0].schemaId = this.matrix.getCheckedNodes().get(0).getAttribute("jsxcode");
				wizard[0].orgId = this.matrix.getCheckedNodes().get(0).getAttribute("jsxOrgid");
				console.log("\r\r\t"+this.matrix.getCheckedNodes().get(0)+"\r");
			}
			wizard[0].loadContent();
		}
		objRoot.prototype.changePage = function(direct){
			//calculate the next page
			this.currPage=this.currPage+direct;
			if (this.currPage < 1) {
				//if pagenum <0 it will be 1 and not move
				this.currPage = 1
				return;
			}
			if (this.currPage>this.totalPage)
			{//if pagenum>totalpage it wiil be total page and not move
				this.currPage=this.totalPage;
				return;
			}
			//require data
			var code=this.getDescendantOfName("blkSearchCode").getDescendantOfName("txtValue").getValue();
			var name=this.getDescendantOfName("blkSearchName").getDescendantOfName("txtValue").getValue();
			var type=this.getDescendantOfName("blkSearchType").getDescendantOfName("selValue").getValue();
			if (code=="")
			{
				code=null;
			}
			if (name=="")
			{
				name=null;
			}
			if (type=="")
			{
				type=null;
			}
			//GetCooperAgreementUCC.getCooperAgreementListByCondition( internalOrgId 内部机构编号-分行, cooperAgreementTypeCode 合作协议类型, cooperAgreementNbr 合作协议编号, partybName 合作机构名称, String curPage, String pageSize)
			ux.megatron.util.Dwr.callDwr("GetCooperAgreementUCC", "getCooperAgreementListByCondition", [null,type,code,name,this.currPage,this.pageSize], this, this.loadSchemaList);
		}
		/**
		 * user select schema type on search bar
		 * @param {Object} select
		 */
		objRoot.prototype.typeSelected = function(select){
			//hold back user select other type
			if (select.getValue()!="004")
			{
				select.setValue(null);
			}
		}
	
	});

}